package org.sunspotworld.util;

public class Units {
    public static final int METERS = 0;
    public static final int CENTIMETERS = 1;
    public static final int MILLIMETERS = 2;
    public static final int INCHES = 3;
    private static final float[] UNITS_PER_METER = {1, 100, 1000, 39.3700787401575F};

    public static float convert(float value, int unitFrom, int unitTo) {
    	// unitFrom * meters/unitFrom * unitTo/meters
    	return value * UNITS_PER_METER[unitTo] / UNITS_PER_METER[unitFrom];
    }

    public static double convert(double value, int unitFrom, int unitTo) {
    	// unitFrom * meters/unitFrom * unitTo/meters
    	return value * UNITS_PER_METER[unitTo] / UNITS_PER_METER[unitFrom];
    }
}
